<?php
namespace Home\Controller;
use Think\Controller;
class RiskcontrolController extends MerchantController {

	public function index(){
		//IP限制列表
		$ip_list=M("ipblock")->where(array("ip_mid"=>$this->merchant_info['mh_id']))->select();
		//国家限制列表
		$cn_list=D("CnblockView")->where(array("cn_mid"=>$this->merchant_info['mh_id']))->select();
		
		$this->assign("ip_list",$ip_list);
		$this->assign("cn_list",$cn_list);
		$this->assign("main_title",L("risk_control"));
		$this->display();
	}
	
	public function addip(){
	try{
		$data["ip_mid"]=$this->merchant_info['mh_id'];
		$data["ip_value"]=I("ip");
		if(M("ipblock")->add($data))
			$this->success(L("add_success"));
		else
			$this->error(L("add_failed"));
		}catch( \Exception $e){
		$this->error($e->getMessage());
		}
	}
	
	public function deleteip(){
	try{
		$con["ip_mid"]=$this->merchant_info['mh_id'];
		$con["ip_id"]=I("path.2");
		if(M("ipblock")->where($con)->delete())
			$this->success(L("delete_success"));
		else
			$this->error(L("delete_failed"));
		}catch( \Exception $e){
		$this->error($e->getMessage());
		}		
	}
	
	public function addcountry(){
	try{
		$data["cn_mid"]=$this->merchant_info['mh_id'];
		$data["cn_value"]=I("country");
		if(M("countryblock")->add($data))
			$this->success(L("add_success"));
		else
			$this->error(L("add_failed"));
		}catch( \Exception $e){
		$this->error($e->getMessage());
		}	
	}

	public function deletecountry(){
	try{
		$con["cn_mid"]=$this->merchant_info['mh_id'];
		$con["cn_id"]=I("path.2");
		if(M("countryblock")->where($con)->delete())
			$this->success(L("delete_success"));
		else
			$this->error(L("delete_failed"));
		}catch( \Exception $e){
		$this->error($e->getMessage());
		}		
	}	
	
}